<?php
class Master_set_Sekali extends CI_Model 
{

	function __construct()
	{
		parent::__construct();
	}
	
	function insert_data($id_tapel,$id_komponen,$nominal,$id_lembaga){
		//$id_lembaga=$this->session->userdata('id_lembaga');
		$data=array('id_tapel'=>$id_tapel,
					'id_komponen'=>$id_komponen,
					'id_lembaga'=>$id_lembaga,
					'nominal'=>$nominal);
		$insert=$this->db->insert('set_pemb_sekali',$data);
		return $insert;
	}
	
	function read($limit, $offset,$id_lembaga)	{
		//$id_lembaga=$this->session->userdata('id_lembaga');
		$sql="select distinct a.id_tapel,b.th_ajaran from set_pemb_sekali a inner join mr_th_ajaran b
			on a.id_tapel=b.id_mr_th_ajaran where id_lembaga='".$id_lembaga."' 
			order by b.th_ajaran asc limit $offset, $limit";
		$query=$this->db->query($sql);
		if ($query->num_rows()>0){
			return $query->result_array();
		}else{
			return array();
		}
	}
	
	function get_detail($id_tapel,$id_lembaga){
		$sql="select a.id_komponen,b.nama_komp,a.nominal from set_pemb_sekali a inner join mr_komp_pembayaran b
				on a.id_komponen=b.id_komp where a.id_tapel='".$id_tapel."' and a.id_lembaga='".$id_lembaga."'";
		//echo $sql;
		$query=$this->db->query($sql);
		if ($query->num_rows()>0){
			return $query->result_array();
		}else{
			return array();
		}
	}
	
	function get_detail_by_komponen($id_tapel,$id_komp){
		$sql="select ifnull(sum(nominal),0) as nominal from set_pemb_sekali where id_tapel='".$id_tapel."' and id_komponen='".$id_komp."'";
		//echo $sql;
		$query=$this->db->query($sql);
		if ($query->num_rows()>0){
			return $query->row_array();
		}else{
			return array();
		}
	}
	
	function count_all_num_rows($id_lembaga){
		$sql="select distinct a.id_tapel,b.th_ajaran from set_pemb_sekali a inner join mr_th_ajaran b
			on a.id_tapel=b.id_mr_th_ajaran where id_lembaga='".$id_lembaga."'";
		$query=$this->db->query($sql);
		return $query->num_rows();
	}
	
	function del_by_tapel($id){
		$this->db->where('id_tapel', $id);
		$delete = $this->db->delete('set_pemb_sekali');
		return $delete;
	}
	
	function cek_pembayaran($id_tapel){
		$sql="select * from mr_siswa where id_tapel_masuk='".$id_tapel."'";
		$query=$this->db->query($sql);
		if ($query->num_rows()>0){
			return true;
		}else{
			return false;
		}
	}
	
}

?>